﻿Imports System.Data
Imports System.Data.OleDb
Partial Class Main_BlogDetails
    Inherits System.Web.UI.Page

    Protected Sub btnPost_Click(sender As Object, e As System.EventArgs) Handles btnPost.Click
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("myFirstDatabase").ConnectionString)
        Dim SqlString As String = "Insert into tblBlogPost(Title,Content,BlogID,BDate,Author) Values (@f1,@f2,@f3,@f4,@f5)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        Dim BDate As DateTime = Now()
        Dim format As String = "ddd MMM yyyy"
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtPostTitle.Text)
        cmd.Parameters.AddWithValue("@f2", txtDescription.Text)
        cmd.Parameters.AddWithValue("@f3", Request.Params("ID"))
        cmd.Parameters.AddWithValue("@f4", BDate.ToString(format))
        cmd.Parameters.AddWithValue("@f5", User.Identity.Name)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("../Main/Blog.aspx")
    End Sub

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("myFirstDatabase").ConnectionString)
            oleDbConn.Open()
            Dim ArtViewSql As String = "INSERT INTO tblBlogViewed(Neighbor, BlogID) VALUES(@f1,@f2)"
            Dim cmd As OleDbCommand = New OleDbCommand(ArtViewSql, oleDbConn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", User.Identity.Name)
            cmd.Parameters.AddWithValue("@f2", Request.Params("ID"))
            cmd.ExecuteNonQuery()
        End If
    End Sub
End Class
